package org.bling.star.client.configuration;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.bling.star.client.server.reciver.BusinessService;
import org.bling.star.common.command.BroadcastCommand;
import org.bling.star.common.command.ServiceCommand;
import org.bling.star.common.command.systems.SystemCommand;
import org.springframework.stereotype.Component;


@Component
public class BusinessHandler extends SimpleChannelInboundHandler<Object> {
    private final BusinessService businessService;

    public BusinessHandler(BusinessService businessService) {
        this.businessService = businessService;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof SystemCommand) {
            SystemCommand connectRequest = (SystemCommand) msg;
        } else if (msg instanceof ServiceCommand) {
            //分发业务流
            BroadcastCommand msg1 = (BroadcastCommand) msg;
            businessService.showTalking(msg1);
        } else {
            ctx.fireChannelRead(msg);
        }
    }
}
